package l1j.server.server.clientpackets;


import l1j.server.echo.ClientThread;

import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.model.L1Party;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_Party;
import l1j.server.server.serverpackets.S_ServerMessage;
/**
 * 處理收到由客戶端傳來隊伍的封包
 */
public class C_Party extends ClientBasePacket {

	private static final String C_PARTY = "[C] C_Party";
	private static final Logger _log = Logger.getLogger(C_Party.class.getName());
	@Override
	public String getType() {
		return C_PARTY;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);
			final L1PcInstance pc = client.getActiveChar();
			if (pc == null || pc.isGhost()) {
				return;
			}
			final L1Party party = pc.getParty();
			if (pc.isInParty()) {
				pc.sendPackets(new S_Party("party", pc.getId(), party.getLeader().getName(), party.getMembersNameList()));
			} else {
				pc.sendPackets(new S_ServerMessage(425)); // パーティーに加入していません。
				// pc.sendPackets(new S_Party("party", pc .getId()));
			}
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);

		} finally {
			this.over();
		}
	}

}
